﻿var scrollCount = 10; // count to allow automatic loading records
var isFisrtLoad = true;
$(document).ready(function () {
    getDataList("");
});

$(window).scroll(function () { //detect page scroll
    //        if ($(window).scrollTop() + $(window).height() == $(document).height())  //user scrolled to bottom of the page?
    //            if (scrollCount > 0)
    //                additionalRecClick();
    try {
        if (document.body.scrollHeight == document.body.scrollTop + window.innerHeight) { //JavaScript - user scrolled to bottom of the page?
            if (scrollCount > 0)
                additionalRecClick();
            else
                $("#f_more").html("Click here to get more records...");
        }
        else
            $("#f_more").html("Click here to get more records...");
    }
    catch (e) {
        $("#f_more").html("Click here to get more records...");
    }
});

//display grid common actions 
function submitform() {
    document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = 1;
    document.aspnetForm.submit();
}
function moveGridPage(page_id) {
    if (eval(page_id) <= 0) //if (page_id <= 0) // changed by Jeya Prabha 
        return false;
    //alert(document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value);
    //alert(document.getElementById("ctl00_ContentPlaceHolder3_hihLastPageId").value);
    var last_page_id = document.getElementById("ctl00_ContentPlaceHolder3_hihLastPageId").value; //var last_page_id=document.getElementById("hihLastPageId").value;
    if (eval(page_id) > eval(last_page_id))//if (page_id > last_page_id) // changed by Jeya Prabha 
        return false;
    document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = page_id; //document.getElementById("hihCurrentPageId").value = page_id;
    return true;
}
function GetEditPageURL() // Added by srivatsan to get Edit page URL
{
    var URLstring = "";
    if (document.getElementById("ctl00_ContentPlaceHolder3_hiheditpageURL") != null) {
        URLstring = document.getElementById("ctl00_ContentPlaceHolder3_hiheditpageURL").value;
    }
    // alert(URLstring);
    return URLstring;
}
function SetFirstPage() {
    resetObjectSearch(false);
    if (document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId") != null) {
        //alert(document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value);
        document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = "1";
    }
    mb_processFilterGo();
    return false;
}
function FilterClick() {
    //alert("inside filter click");
    resetObjectSearch(true);
    if (document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick") != null) {
        //alert("controlfound");
        //if(document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick").value=="0" || document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick").value =="")
        // {
        document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick").value = "1";
        //}
        // else
        // {
        //   document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick").value = "0";
        // }
    }
}
function DeleteClick(strDelPK, intCurrentPage) {
    if (document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteafrowid") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteafrowid").value = strDelPK;
        //alert(strDelPK);
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = intCurrentPage;
        //alert(intCurrentPage);
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteClick") != null) {
        //alert("delete clicked");
        document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteClick").value = "1";
    }
}
function interceptObjectSearch(ee) {
    try {
        //            if (document.layers)
        //                Key = ee.which;
        //            else
        //                Key = window.event.keyCode;            
        //            if (Key == 13)
        var code = (ee.keyCode ? ee.keyCode : ee.which); // Added by 'Imran Gani' on 10-Dec-2013, to get enter key value from event
        if (code == 13) {
            //alert("Key pressed! ASCII-value: " + Key);
            var ret = doObjectSearch();
            //            if (ret == true) __doPostBack('', ''); // Commented by 'Imran Gani' on 24-Sep-2014, to avoid postback for search
            //            return false;
        }
    }
    catch (Exintercept) { }
}
function doObjectSearch() {
    try {
        if (document.getElementById("ctl00_ContentPlaceHolder3_txtObjectSearch") != null) {
            var strObjectSearch = document.getElementById("ctl00_ContentPlaceHolder3_txtObjectSearch").value;
            if (strObjectSearch.length < 1) {
                alert("Please enter a search string to continue.");
                return false;
            }
            else if (strObjectSearch == "Record Search") {
                alert("Please enter a search string to continue.");
                return false;
            }
            getDataList(strObjectSearch); // Added by 'Imran Gani' on 24-Sep-2014, to load searched records through ajax
            if (document.getElementById('ctl00_ContentPlaceHolder3_lblListHeader') != null)
                document.getElementById('ctl00_ContentPlaceHolder3_lblListHeader').innerHTML = "Search results for <b>\"" + strObjectSearch + "\"</b>";
            document.getElementById('table51').style.display = 'none';
            document.getElementById('mb_filter_img').style.display = 'block';
        }
        if (document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId") != null) {
            document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = "1";
        }
        if (document.getElementById("ctl00_ContentPlaceHolder3_hfObjectSearch") != null) {
            document.getElementById("ctl00_ContentPlaceHolder3_hfObjectSearch").value = "search";
        }
    }
    catch (ExSearch) { }
    return true;
}
function resetObjectSearch(resetSearchText)//was used in "View all" link, to be removed if no other issues arise from view all
{
    try {
        if (document.getElementById("ctl00_ContentPlaceHolder3_hfObjectSearch") != null)
            document.getElementById("ctl00_ContentPlaceHolder3_hfObjectSearch").value = "";
        if (resetSearchText == true) {
            if (document.getElementById("ctl00_ContentPlaceHolder3_txtObjectSearch") != null)
                document.getElementById("ctl00_ContentPlaceHolder3_txtObjectSearch").value = "";
            if (document.getElementById('ctl00_ContentPlaceHolder3_lblListHeader') != null)
                document.getElementById('ctl00_ContentPlaceHolder3_lblListHeader').innerHTML = "";
        }
    }
    catch (ExResetSearch) { }
}
function mb_datasrch_txt_focus(th) {
    try {
        document.getElementById('ctl00_ContentPlaceHolder3_ImageButton1').src = "Images/objectSearch2.gif";
        if (th.value == "Record Search") {
            th.value = "";
        }
        mb_datasrch_changetxtStyle();
        th.select();
    }
    catch (Ex_mb_datasrch) { }
}
function mb_datasrch_txt_blur(th) {
    try {
        document.getElementById('ctl00_ContentPlaceHolder3_ImageButton1').src = "Images/objectSearch2_disabled.gif";
        if (th.value == "")
            th.value = "Record Search";
        mb_datasrch_changetxtStyle();
    }
    catch (Ex_mb_datasrch) { }
}
function mb_datasrch_changetxtStyle() {
    document.getElementById('ctl00_ContentPlaceHolder3_txtObjectSearch').style.color = document.getElementById('ctl00_ContentPlaceHolder3_txtObjectSearch').value == 'Record Search' ? '#808080' : '#000000';
}
function mb_datasrch_img_focus() {
    document.getElementById('ctl00_ContentPlaceHolder3_ImageButton1').src = "Images/objectSearch2.gif";
}
function mb_datasrch_img_blur() {
    document.getElementById('ctl00_ContentPlaceHolder3_ImageButton1').src = "Images/objectSearch2_disabled.gif";
}
function mb_processFilterGo() {
    var filterNode = document.getElementById("table51");
    if (filterNode == null)
        return false;
    //var anchorNodes = fromParentNode.getElementsByTagName("a");
    var mb_loca = document.location.href;
    var curVariables = mb_getCurUrlVariables();
    var newVariables = [], hash;
    var inputNodes = filterNode.getElementsByTagName("select");
    //add filter flag
    newVariables.push('flmode');
    newVariables['flmode'] = '1';
    var isActuallyFilterORReset = false; //identify users selects --all-- for all.
    for (var i = 0; i < inputNodes.length; i++) {
        newVariables.push(inputNodes[i].id.replace('ctl00_ContentPlaceHolder3_Quick_Search_', ''));
        newVariables[inputNodes[i].id.replace('ctl00_ContentPlaceHolder3_Quick_Search_', '')] = escape(inputNodes[i].value);
        isActuallyFilterORReset = isActuallyFilterORReset == true ? true : (isActuallyFilterORReset == (inputNodes[i].value == '--All--'));
    }
    if (isActuallyFilterORReset == false)//users tried to reset filter
    {
        mb_loadViewAllUrl();
        return false;
    }
    // added by 'Imran Gani' on 27-Jun-2013, to append a parameter for page view type in URL
    newVariables.push('pgtype');
    newVariables['pgtype'] = $('#ctl00_ContentPlaceHolder3_ddlPageViewType').val();
    //remove old variables when new exists
    var mb_go_url = window.location.href.substr(0, window.location.href.indexOf('?'));
    for (var i = 0; i < newVariables.length; i++) {
        if (curVariables[newVariables[i]] == undefined)//not exists
        {
            curVariables.push(newVariables[i]);
            curVariables[newVariables[i]] = newVariables[newVariables[i]];
        }
        else //exists
        {
            curVariables[newVariables[i]] = newVariables[newVariables[i]]; //fix this later
        }
    }
    getDataList("", curVariables); // Added by 'Imran Gani' on 24-Sep-2014, to load filtered records through ajax
    if (document.getElementById('ctl00_ContentPlaceHolder3_lblListHeader') != null)
        document.getElementById('ctl00_ContentPlaceHolder3_lblListHeader').innerHTML = "Filtered view. Click <a href='#' onclick='javascript:mb_loadViewAllUrl();return false;'>here</a> to view all records.";
    mb_disableFilterInvokeButton();
    //
    //    for (var i = 0; i < curVariables.length; i++) {  // Commented by 'Imran Gani' on 24-Sep-2014, to avoid postback for search
    //        mb_go_url += (i == 0 ? '?' : '&') + curVariables[i] + "=" + curVariables[curVariables[i]];
    //    }
    //    document.location.href = mb_go_url;
}
function mb_getCurUrlVariables() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = escape(hash[1]);
    }
    return vars;
}
function mb_loadViewAllUrl() {
    try {
        var vieAllNodes = document.getElementById('ctl00_ltaccordian').getElementsByTagName("a");
        var loadUrl = vieAllNodes[vieAllNodes.length - 1].getAttribute('href');
        if (loadUrl.length > 0)
            window.location.href = loadUrl;
    }
    catch (ex_mb_vieall) {
        alert("Unable to load the page. Please use the menu to navigate");
    }
}
function mb_updateGoButton() {
    try {
        document.getElementById('ctl00_ContentPlaceHolder3_btngo').value = ' Go ';
        var filterNode = document.getElementById("table51");
        if (filterNode == null)
            return false;
        var inputNodes = filterNode.getElementsByTagName("select");
        var isActuallyFilterORReset = false; //identify users selects --all-- for all.
        for (var i = 0; i < inputNodes.length; i++) {
            isActuallyFilterORReset = isActuallyFilterORReset == true ? true : (isActuallyFilterORReset == (inputNodes[i].value == '--All--'));
            if (isActuallyFilterORReset == true) break;
        }
        if (isActuallyFilterORReset == false)//users tried to reset filter
        {
            document.getElementById('ctl00_ContentPlaceHolder3_btngo').value = 'View All';
        }
    }
    catch (ex_mb_updtgo) {}
}
function mb_disableFilterInvokeButton() {
    try {
        if (document.getElementById('ctl00_ContentPlaceHolder3_btngo') != null && document.getElementById('table51') != null)//filter mode
        {
            document.getElementById('mb_filter_img').style.display = 'none';
        }
    }
    catch (ex_mb_disbflbtn) { }
}

/********************Search process*******************/
function additionalRecClick() {
    var iObjectID = $("#ctl00_ContentPlaceHolder3_hfObjectRowID").val();
    $("#ctl00_ContentPlaceHolder3_Object" + iObjectID + "_MORE a").click();
}

function getDataList(srhText, curVariables) {
    try {
        var DynamicDivResults = document.getElementById("ctl00_ContentPlaceHolder3_tdDisplayGrid");
        DynamicDivResults.innerHTML = "";
        if (curVariables == null || curVariables == 'undefined')
            curVariables = mb_getCurUrlVariables();
        $("#ctl00_ContentPlaceHolder3_lblMessage").html("");
        var iObjectID = $("#ctl00_ContentPlaceHolder3_hfObjectRowID").val();
        var pgDetails = "";
        GenerateObjectHeader(iObjectID, DynamicDivResults);
        doAjaxProcess(srhText, iObjectID, pgDetails, curVariables);
    }
    catch (e){ }
}

function doAjaxProcess(srhText, iObjectID, pgDetails, curVariables) {
    try {
        if (curVariables == null || curVariables == 'undefined')
            curVariables = mb_getCurUrlVariables();
        var pgURL = "";
        for (var i = 0; i < curVariables.length; i++) {
            pgURL += '&' + curVariables[i] + "=" + curVariables[curVariables[i]];
        }
        $.ajax({
            url: "mb_ajaxhandler.aspx?action=data_search&data=" + escape(srhText) + "&val=" + iObjectID + "&pgInfo=" + pgDetails + pgURL,
            dataType: "json",
            cache: false,
            beforeSend: function () { LoadingImage(iObjectID, "REQUEST", ""); },
            success: function (respObj) {
                if (respObj.NORECORD) {
                    var msg = respObj.NORECORD;
                    LoadingImage(iObjectID, "RESPONSE", msg);
                }
                else
                    BuildObjectItems(srhText, respObj, iObjectID);
                scrollCount -= 1;
            },
            complete: function () {
                if (isFisrtLoad)
                    if (window.innerHeight >= $("#ctl00_div_content").height() + 100)
                        additionalRecClick();
                    else
                        isFisrtLoad = false;
            },
            error: function (msg) { }
        });
    }
    catch (e) { }
}

/***********Code For Generating the Object Div**********************/

function GenerateObjectHeader(srhStorageObjectId, dynamicObjectDiv) {
    if (dynamicObjectDiv) {
        var catHolderDiv = new createObjectDiv(srhStorageObjectId);
        catHolderDiv.addObjectTable();
        catHolderDiv.addObjectMore();
        dynamicObjectDiv.appendChild(catHolderDiv.getCreatedObjectDiv());
    }
}

function createObjectDiv(srhStorageObjectId) {
    this.holderdiv = document.createElement("div");
    this.holderdiv.style.margin = "0px 0px 10px 0px";
    this.ObjectStorageValue = srhStorageObjectId;
}
createObjectDiv.prototype.addObjectTable = function () {
    var CatTable = document.createElement("table");
    CatTable.id = "ctl00_ContentPlaceHolder3_Object" + this.ObjectStorageValue + "_TABLE";

    CatTable.width = "100%";
    //CatTable.height = "1%";
    CatTable.cellPadding = 0;
    CatTable.cellSpacing = 0;
    CatTable.border = 0;
    var CatTableBody = document.createElement('tbody');
    CatTable.appendChild(CatTableBody);
    this.holderdiv.appendChild(CatTable);
}
createObjectDiv.prototype.addObjectMore = function () {
    var CatMoreDiv = document.createElement("div");
    CatMoreDiv.innerHTML = "&nbsp;";
    CatMoreDiv.className = "CategoryMoreDiv";
    CatMoreDiv.id = "ctl00_ContentPlaceHolder3_Object" + this.ObjectStorageValue + "_MORE";
    this.holderdiv.appendChild(CatMoreDiv);
}
createObjectDiv.prototype.getCreatedObjectDiv = function () {
    return this.holderdiv;
}
/******************End of Object Header Function****************/

/********************Common Methods************************/
function LoadingImage(cid, key, msg) {
    var moredivobj = get_object("ctl00_ContentPlaceHolder3_Object" + cid + "_MORE");
    if (key == "REQUEST") {
        if (moredivobj)
            moredivobj.innerHTML = "&nbsp;<img src=\"Images/load.gif\" style=\"width:15px;Padding-top:3;\">&nbsp;&nbsp;Loading...";
    } else if (key == "RESPONSE") {
        if (moredivobj)
            moredivobj.innerHTML = "";
        if (msg != "")
            moredivobj.innerHTML = msg;
    }
}

function get_object(id) {
    var object = null;
    if (document.layers)
        object = document.layers[id];
    else if (document.all)
        object = document.all[id];
    else if (document.getElementById)
        object = document.getElementById(id);
    return object;
}
/********************End Of Common Methods************************/

/********************Code the generate grid list************************/

function BuildObjectItems(srhText, respObj, ObjectId) {
    var pageDetails = "";
    if (respObj.PAGEINFO)
        pageDetails = respObj.PAGEINFO[0].PAGEDETAILS;

    if (respObj.SCHEMA) {
        var colArray = new Array();
        var colDataType = new Array();
        for (var tindex = 0; tindex < respObj.SCHEMA.length; tindex++) {
            colArray[tindex] = respObj.SCHEMA[tindex].CNAME;
            colDataType[tindex] = respObj.SCHEMA[tindex].DTYPE;
        }
    }

    if (colArray.length > 0) {
        var ObjectTableId = "ctl00_ContentPlaceHolder3_Object" + ObjectId + "_TABLE";
        var ObjectMoreId = "ctl00_ContentPlaceHolder3_Object" + ObjectId + "_MORE";
        var ObjectItemTable = get_object(ObjectTableId);

        var rowObj = new generateObjectRow(colArray, colDataType, respObj);
        var trRowArray = rowObj.getObjectRowArray();

        var tbodyObj = ObjectItemTable.getElementsByTagName("tbody")[0];

        /*************** To Find The Child Nodes css Start Index *****************/
        var tBodyChildCount = getTrCountValue(tbodyObj.childNodes);
        var cssGridStartIndex = "0";
        if (parseInt(tBodyChildCount) > 0) {
            if (parseInt(tBodyChildCount) % 2 == 0)
                cssGridStartIndex = "1";
        }
        else {
            var trRowHeader = rowObj.getObjectRowHeader();
            tbodyObj.appendChild(trRowHeader);
        }
        /**************************************************************************/
        if (trRowArray.length > 0) {
            for (var index = 0; index < trRowArray.length; index++) {
                trRowArray[index].className = "Grid_Row" + cssGridStartIndex;

                trRowArray[index].onmouseover = function () {
                    this.className = 'Grid_Scroll_BG'
                }

                trRowArray[index].val = cssGridStartIndex;

                trRowArray[index].onmouseout = function () {
                    this.className = "Grid_Row" + this.val;
                }

                tbodyObj.appendChild(trRowArray[index]);
                cssGridStartIndex = cssGridStartIndex != "0" ? "0" : "1";
            }
            LoadingImage(ObjectId, "RESPONSE", "");
            var MoreDivId = "ctl00_ContentPlaceHolder3_Object" + ObjectId + "_MORE";
            var moredivObj = get_object(MoreDivId);
            if (moredivObj)
                moredivObj.innerHTML = "<a href=\"javascript:;\" onclick=\"doAjaxProcess('" + srhText + "','" + ObjectId + "','" + pageDetails + "')\" ><font id='f_more' color='blue'>More...</font></a>";
        }
        else {
            var trObj = document.createElement('tr');
            trObj.className = "Grid_Row" + cssGridStartIndex;
            for (var cindex = 0; cindex < colArray.length; cindex++) {
                var tdObj = document.createElement('td');
                if (cindex == 1)
                    tdObj.innerHTML = "No Records Available.";
                trObj.appendChild(tdObj);
            }
            rowObj.setStyle(trObj);
            tbodyObj.appendChild(trObj);
            LoadingImage(ObjectId, "RESPONSE", "");
        }
    }
}

function getTrCountValue(tBodyObj) {
    var intCount = 0;
    if (tBodyObj.length > 0) {
        for (var index = 0; index < tBodyObj.length; index++) {
            if (tBodyObj[index].tagName == 'TR')
                intCount++;
        }
    }
    return intCount;
}

function generateObjectRow(colarray, colDatatype, JsonRespObj) {
    this.ColArray = colarray;
    this.ColDataType = colDatatype;
    this.DataRowObj = JsonRespObj.DATA;
    this.PageAccess = JsonRespObj.PAGEACCESS;
    if (JsonRespObj.hasOwnProperty("ACTION"))
        this.Action = JsonRespObj.ACTION;
    this.PagesetId = JsonRespObj.PAGEINFO[0].PAGESETID;
    this.MenuId = JsonRespObj.PAGEINFO[0].MENUID;
    this.EditPage = JsonRespObj.PAGEINFO[0].EDITPAGE;
    this.trRowArray = new Array();
}

generateObjectRow.prototype.getObjectRowHeader = function () {
    var trObj = document.createElement('tr');
    trObj.className = "Grid_Header";
    for (var cindex = 0; cindex < this.ColArray.length; cindex++) {
        var tdObj = document.createElement('td');
        this.setAlignment(tdObj, this.ColDataType[cindex]);
        tdObj.className = "Grid_Header_Cell";
        tdObj.valign = "middle";
        if (this.ColArray[cindex].trim().toUpperCase() != "KEYS")
            tdObj.innerHTML = this.ColArray[cindex] + "&nbsp";
        trObj.appendChild(tdObj);
    }
    return trObj;
}

generateObjectRow.prototype.getObjectRowArray = function () {
    var EditPage = this.EditPage;
    var strMenuRowId = this.MenuId;
    var pgs_id = this.PagesetId;
    if (this.DataRowObj != null) {
        for (var rindex = 0; rindex < this.DataRowObj.length; rindex++) {
            var trObj = document.createElement('tr');
            for (var cindex = 0; cindex < this.ColArray.length; cindex++) {

                var tdObj = document.createElement('td');
                this.setAlignment(tdObj, this.ColDataType[cindex]);
                trObj.appendChild(tdObj);
                if (this.ColArray[cindex].trim().toUpperCase() == "KEYS") {

                    var cellValue = this.DataRowObj[rindex][this.ColArray[cindex]];
                    var firstcellvalue = this.DataRowObj[rindex][this.ColArray[1]];

                    trObj.id = "ctl00_ContentPlaceHolder3_ObjectAF_ROW_ID _" + cellValue;

                    this.appendAccessPermissionIcons(tdObj, cellValue, EditPage, strMenuRowId, pgs_id, firstcellvalue);

                } else {

                    var displayField = "";
                    var cellValue = this.DataRowObj[rindex][this.ColArray[cindex]];
                    displayField = cellValue;
                    if (cindex == 1) {
                        var strText = "";
                        var keyValue = this.DataRowObj[rindex]['keys'];
                        strText = "" + EditPage + "?pgs_id=" + pgs_id + "&PK=" + keyValue;
                        strText += "&mn=" + strMenuRowId + "&VMODE=1";
                        displayField = "<a href=\"" + strText + "\"><font color='blue'>" + displayField + "</font></a>";
                    }
                    if (cellValue == null)
                        tdObj.innerHTML = "&nbsp";
                    else
                        tdObj.innerHTML = displayField + "&nbsp";
                }
            }
            this.setStyle(trObj);
            this.trRowArray[this.trRowArray.length] = trObj;
        }
    }
    return this.trRowArray;
}


generateObjectRow.prototype.appendAccessPermissionIcons = function (tdObj, cellValues, EditPage, strMenuRowId, pgs_id, firstcellvalue) {
    try {
        var bRead = this.PageAccess[0]["READ"] == "True" ? true : false;
        var bCreate = this.PageAccess[0]["CREATE"] == "True" ? true : false;
        var bEdit = this.PageAccess[0]["EDIT"] == "True" ? true : false;
        var bDelete = this.PageAccess[0]["DELETE"] == "True" ? true : false;
        var bAction = this.PageAccess[0]["ACTION"] == "True" ? true : false;

        var tempTableStr = "";
        var EditStr = "";
        var CopyStr = "";
        var DeleteStr = "";
        var appendEditIcons = false;
        tempTableStr = "<table border='0' cellpadding='0' cellspacing='0'><tr>";
        var strText = "";
        if (bEdit) {
            strText = "" + EditPage + "?pgs_id=" + pgs_id + "&PK=" + cellValues;
            strText += "&mn=" + strMenuRowId + "";
            tempTableStr += "<td width=\"25px\"><a style='text-decoration:none;' href=\"" + strText + "\">" + "<img border='0' style='cursor:pointer' onclick=\"javascript:this.src='images/load.gif'\" title='Edit' src=\"images/edit.gif\"></a></td>";
            appendEditIcons = true;
        }
        if (bCreate) {
            strText = "" + EditPage + "?pgs_id=" + pgs_id + "&PK=" + cellValues;
            strText += "&mn=" + strMenuRowId + "&CPY=0";
            tempTableStr += "<td width=\"25px\"><a style='text-decoration:none;' href=\"" + strText + "\">" + "<img border='0' style='cursor:pointer' onclick=\"javascript:this.src='images/load.gif'\" title='Copy' src=\"images/copy.gif\"></a></td>";
            appendEditIcons = true;
        }
        if (bDelete) {
            strText = "";
            tempTableStr += "<td width=\"25px\"><a style='text-decoration:none;' href=\"javascript:;\" onclick=\"DeleteCategoryRow(this,'" + escape(firstcellvalue) + "','" + cellValues + "','" + pgs_id + "','Img_" + cellValues + "_Id')\">" + "<img border='0' id = 'Img_" + cellValues + "_Id' style='cursor:pointer'  title='Delete' src=\"images/delete.gif\"></a></td>";
            appendEditIcons = true;
        }
        if (bAction && this.Action.length > 0) {
            strText = "";
            tempTableStr += "<td width=\"25px\" onmouseover=\"javascript:ShowDivForActions('div_Ac_" + cellValues + "');\" onmouseout=\"javascript:HideDivForActions('div_Ac_" + cellValues + "');\" ><input id=\"ctl00_ContentPlaceHolder3_Ac_" + cellValues + "\" type=\"image\" name=\"ctl00$ContentPlaceHolder3$Ac_" + cellValues + "\" src=\"images/action_16.gif\" style=\"border-width:0px;\"><br><span id=\"ctl00_ContentPlaceHolder3_div_Ac_" + cellValues + "\" class=\"Grid_Row_actions\" style=\"border-color: graytext; border-width: 1px; border-style: solid; display: none; position: absolute;\" onmouseout=\"javascript:HideDivForActions('div_Ac_" + cellValues + "');\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"GrayText\" border=\"0\" style=\"border-bottom:1px;border-top:1px;border-left:1px;border-right:1px;\"><tbody><tr><td nowrap=\"nowrap\"><span class=\"controlFont pgForm_title\" style=\"display:inline-block;width:100%;\"><img src=\"Images/action_16.gif\" style=\"vertical-align:bottom\"><span style=\"vertical-align:bottom\">&nbsp;Actions</span></span></td></tr><tr><td nowrap=\"nowrap\"><span class=\"controlFont Grid_Row_actions\" style=\"display:inline-block;width:100%;\" title=\"" + this.Action[0]["dsc"] + "\">&nbsp; <a href=\"" + this.Action[0]["url"] + "&ID=" + cellValues + "&action=1\">" + this.Action[0]["name"] + "</a> &nbsp;</span><span class=\"Grid_Row_actions\"></span></td></tr></tbody></table></span></td>"
            appendEditIcons = true;
        }
        tempTableStr += "</tr></table>";
        if (appendEditIcons) {
            if (bAction && this.Action.length > 0)
                tdObj.width = '100px';
            else
                tdObj.width = '80px';
            tdObj.innerHTML = tempTableStr;
            //        } else {
            //            tdObj.parentNode.removeChild(tdObj);
        }
    }
    catch (ee) { }
}

generateObjectRow.prototype.setStyle = function (trRowArray) {
    if (trRowArray.childNodes.length > 0) {
        trRowArray.childNodes[0].className = 'leftGrid';
        if (trRowArray.childNodes[0].innerHTML == "")
            trRowArray.childNodes[0].innerHTML = "&nbsp;"
    }

    if (trRowArray.childNodes.length > 1) {
        trRowArray.childNodes[parseInt(trRowArray.childNodes.length) - 1].className = 'rightGrid';
        if (trRowArray.childNodes[parseInt(trRowArray.childNodes.length) - 1].innerHTML == "")
            trRowArray.childNodes[parseInt(trRowArray.childNodes.length) - 1].innerHTML = "&nbsp;"
    }
}

generateObjectRow.prototype.setAlignment = function (tdObj, DataType) {
    switch (DataType) {
        case "BO":
        case "DA":
        case "DT":
        case "TX":
            tdObj.align = "Left";
            break;
        case "CU":
        case "DC":
        case "NU":
        case "AN":
            tdObj.align = "Right";
            break;
        default:
            tdObj.align = "center";
            break;
    }
}

function DeleteCategoryRow(obj, nodeText, key, strPageSetId, imageId) {
    var cmsg = confirm("Are you sure you want to delete " + unescape(nodeText) + " ?\r Note: Child records will also be deleted.");
    if (cmsg) {
        var url = "DisplayGrid.aspx?pgs_id=" + strPageSetId + "&DPK=" + key;
        var tbodyObject = obj.parentNode.parentNode.parentNode;
        var tCurrRowObject = obj.parentNode.parentNode;
        if (imageId != "") {
            var ImageID = get_object(imageId);
            ImageID.src = "images/Load.gif";
        }
        AJAX_call(obj, url, nodeText);
    }
}

function AJAX_call(obj, url, node) {
    if (url == "")
        return;
    else
        url += "&DeleteAjaxTreeCall= true";
    try {
        var xmlHttp_fb;
        var node = node;
        var tree = tree;
        try {
            // Firefox, Opera 8.0+, Safari
            xmlHttp_fb = new XMLHttpRequest();
        } catch (e) {
            // Internet Explorer
            try {
                xmlHttp_fb = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp_fb = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    //alert("Your browser does not support AJAX!");
                    return false;
                }
            }
        }
        xmlHttp_fb.onreadystatechange = function () {
            if (xmlHttp_fb.readyState == 1) {
                //document.getElementById("ctl00_fb_status").innerHTML = "<img src='Images/load.gif' border='0'></img>&nbsp;Submitting...";
            }
            if (xmlHttp_fb.readyState == 4) {
                var responseText = xmlHttp_fb.responseText;
                if (responseText.toUpperCase() == "TRUE")
                    removeCategoryRowObject(obj);
            }
        }
        var http_date = new Date()
        xmlHttp_fb.open("GET", url, true);
        xmlHttp_fb.send(null);
    } catch (Exxx) { }
}


function removeCategoryRowObject(obj) {
    var tCurrRowObject = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
    //alert ("The Element Id is " + tCurrRowObject.id );
    var tbodyObject = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
    var temptBodyObject = tbodyObject;
    if (tbodyObject) {
        var tCurrRowObject = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
        disableDeletedRow(tbodyObject, tCurrRowObject);
    }
}

function disableDeletedRow(tBodyObject, tDeletedRowObject) {

    var childNodelen = tBodyObject.childNodes.length;
    if (tBodyObject) {
        for (var index = 0; index < tBodyObject.childNodes.length; index++) {
            if (tBodyObject.childNodes[index] === tDeletedRowObject) {
                tBodyObject.childNodes[index].parentNode.removeChild(tBodyObject.childNodes[index]);

                if (getTrPresentStatus(tBodyObject)) {
                    reAssignCss(tBodyObject, index);
                    return;
                } else {
                    removeCategoryHeader(tBodyObject);
                    return;
                }
            }
        }
    }
}

function removeCategoryHeader(tBodyObject) {
    var parentHolderDiv = tBodyObject.parentNode.parentNode;
    parentHolderDiv.parentNode.removeChild(parentHolderDiv);
}

function getTrPresentStatus(tBodyObject) {
    var TrStatus = false;
    for (var index = 0; index < tBodyObject.childNodes.length; index++) {
        if (tBodyObject.childNodes[index].tagName == 'TR')
            TrStatus = true;
    }
    return TrStatus;
}

function reAssignCss(tBodyObject, rindex) {
    var itemindex = rindex;
    for (index = rindex; index < tBodyObject.childNodes.length; index++) {
        if (tBodyObject.childNodes[index].tagName == 'TR') {

            var className = tBodyObject.childNodes[index].className.trim();
            var previouscssIndex = className.substr(8, 1);
            var cssIndex = previouscssIndex == "1" ? "0" : "1";

            tBodyObject.childNodes[index].className = 'Grid_Row' + cssIndex;
            tBodyObject.childNodes[index].val = cssIndex;

            tBodyObject.childNodes[index].onmouseout = function () {
                this.className = "Grid_Row" + this.val;
            }
            itemindex++;
        }
    }
}

/********************End of grid list************************/